const teamSchema = require('./schema/teamSchema')

const teamModel = {}

teamModel.addTeamMember = (member) => {
  const data = new teamSchema({
    name: member.name,
    enname: member.enname,
    title: member.title,
    jieshao: member.jieshao,
    photo: member.photo,
    type: member.type
  })
  return new Promise((resolve, reject) => {
    data.save((err, res) => {
      if(err) {
        reject(err)
      } else {
        resolve(res)
      }
    })
  })
}

teamModel.getTeamList = (type) => {
  const type1 = {}
  if (type) {
    type1 = {
      type: Number(type)
    }
  }
  return new Promise((resolve, reject) => {
    teamSchema.find(type1).exec((err, rows) => {
      if (err) {
        reject(err)
      } else {
        resolve(rows)
      }
    })
  })
}

module.exports = teamModel
